using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Xml.Linq;

namespace Teele
{
    public static class XmlParser
    {
        public static List<SpeedCamContainer> Parse(Stream stream)
        {
            if (stream != null)
            {
                XElement xml = XElement.Load(stream);

                XElement current = (XElement) xml.FirstNode;
                List<SpeedCamContainer> list = new List<SpeedCamContainer>();
                do
                {
                    current = (XElement) current.NextNode;

                    if (current== null)
                    {
                        break;
                    }
                    //  var latt=  current.Attribute("lat");
                    SpeedCamContainer speedCamContainer = new SpeedCamContainer();
                    speedCamContainer.id = current.Attribute("id").Value;
                    speedCamContainer.longitude = current.Attribute("lng").Value;
                    speedCamContainer.latitude = current.Attribute("lat").Value;
                    speedCamContainer.name = current.Attribute("name").Value;
                    speedCamContainer.MaxSpeed = Int32.Parse(current.Attribute("clinf").Value);

                    list.Add(speedCamContainer);
                } while (current != null);

                return list;
            }
            return new List<SpeedCamContainer> ();
        }

        public class SpeedCamContainer
        {
            public string id;
            public string longitude;
            public string latitude;
            public string name;
            public int MaxSpeed;

            public double GetLongitude()
            {
                CultureInfo cu = new CultureInfo("en-US");
                return double.Parse(longitude,cu);
            }
            public double GetLatitude()
            {
                CultureInfo cu = new CultureInfo("en-US");
                return double.Parse(latitude,cu);
            }
        }
    }
}